package edu.hawaii.myisern.model;

import java.io.File;
import java.io.FileReader;

/**
 * Utility to access test directory files.
 * 
 * @author Randy Cox
 * 
 */
public class Utility {

  /** Max file size. */
  public static final int MAX_FILE_SIZE = 10000;

  /**
   * Utility to retrieve test data in a specified file.
   * 
   * @param filename File that holds expected results.
   * @return expectedStr String with expected results.
   */
  public static String readTextData(String filename) {

    File testDataFile = new File(filename);
    FileReader fileReader = null;
    char[] testData = new char[MAX_FILE_SIZE];

    try {
      fileReader = new FileReader(testDataFile);
      fileReader.read(testData);
    }
    catch (Exception e) {
      String msg = "Utility.readTextData() IO Exception: " + filename;
      msg = msg.concat(" " + e.getMessage());
      Log.error(msg);
      throw new RuntimeException(msg, e);
    }

    String expectedStr = new String(testData);
    expectedStr = expectedStr.replaceAll("\r", "");
    expectedStr = expectedStr.trim();
    return expectedStr;
  }

  /**
   * Utility to retrieve XML data in a specified file.
   * 
   * @param filename File that holds XML.
   * @return expectedStr String with XML data in string format.
   * @throws Exception In case there is an error accessing the file.
   */
  // public static String readXmlData(String filename) throws Exception {
  //
  // File testDataFile = new File(filename);
  //
  // FileReader fileReader = null;
  // fileReader = new FileReader(testDataFile);
  //
  // char[] testData = new char[MAX_FILE_SIZE];
  // fileReader.read(testData);
  //
  // String expectedStr = new String(testData);
  // return expectedStr;
  // }
  /**
   * Utility to remove whitespace from a line.
   * 
   * @param str to remove white space from.
   * @return line with no whitespace.
   */
  // public static String clean(String str) {
  // String line = str;
  // line = line.replace("\n", "");
  // line = line.replace("\r", "");
  // line = line.replace(" ", "");
  // line = line.trim();
  // return line;
  // }
}
